from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from goods.models import SpecificationOption, SPUSpecification
from meiduo_admin.serializer.specificationoption import specificationoptionserializer, SPUSpecificationSerializer

from meiduo_admin.utils import UserPageNum


class SpecificationoptionView(ModelViewSet):

    # 指定查询集
    queryset = SpecificationOption.objects.all()
    # 指定序列化器
    serializer_class = specificationoptionserializer
    # 指定分页器
    pagination_class = UserPageNum
    # 指定权限
    permission_classes = [IsAdminUser]

    def simple(self,request):

        data = SPUSpecification.objects.all()
        ser = SPUSpecificationSerializer(data,many=True)
        return Response(ser.data)